/*     */ package com.newcrm.webapi.sub;
/*     */ 
/*     */ import com.newcrm.bean.CompanyInfo;
/*     */ import com.newcrm.bean.User;
/*     */ import com.newcrm.db.CompanyExtManager;
/*     */ import com.newcrm.db.UserVOIPManager;
/*     */ import com.newcrm.exception.NotFoundException;
/*     */ import com.newcrm.util.PhoneBoxUtil;
/*     */ import com.newcrm.util.Util;
/*     */ import com.newcrm.webapi.AbstractAction;
/*     */ import com.newcrm.webapi.AbstractHttpServlet;
/*     */ import java.io.IOException;
/*     */ import java.io.PrintWriter;
/*     */ import java.util.Date;
/*     */ import java.util.List;
/*     */ import java.util.Map;
/*     */ import javax.servlet.ServletException;
/*     */ import javax.servlet.http.HttpServletRequest;
/*     */ import javax.servlet.http.HttpServletResponse;
/*     */ import org.apache.log4j.Logger;
/*     */ 
/*     */ public class ListAllCallRecords extends AbstractAction
/*     */ {
/*  34 */   private static Logger logger = Logger.getLogger(ListAllCallRecords.class
/*  35 */     .getName());
/*     */ 
/*     */   public ListAllCallRecords(AbstractHttpServlet servlet)
/*     */   {
/*  38 */     super(servlet);
/*     */   }
/*     */ 
/*     */   public void parse(HttpServletRequest request, HttpServletResponse response)
/*     */     throws IOException, ServletException, NotFoundException
/*     */   {
/*  48 */     String phone = Util.getURLParameter(request.getParameter("phone"));
/*  49 */     String seatNum = Util.getURLParameter(request.getParameter("seatNum"));
/*     */ 
/*  51 */     String beginDate = Util.getURLParameter(request
/*  52 */       .getParameter("beginDate"));
/*  53 */     int minTime = Util.getURLIntParameter(request.getParameter("minTime"));
/*  54 */     int maxTime = Util.getURLIntParameter(request.getParameter("maxTime"));
/*     */ 
/*  56 */     int offset = Util.getURLIntParameter(request.getParameter("Offset"));
/*     */ 
/*  58 */     response.setContentType("text/html;charset=utf-8");
/*  59 */     PrintWriter out = response.getWriter();
/*     */ 
/*  62 */     User user = super.getLoginUser(request);
/*     */ 
/*  65 */     if ((!user.isAdmin) && (!user.isGroupAdmin) && (
/*  66 */       (seatNum == null) || (seatNum.trim().length() == 0))) {
/*  67 */       logger.warn("seatNum is null");
/*  68 */       showErrorMessage(response, "系统设置中，没有设置呼叫中心账号和密码信息");
/*  69 */       return;
/*     */     }
/*     */ 
/*  74 */     CompanyExtManager companyExtManager = new CompanyExtManager();
/*  75 */     String companyId2 = companyExtManager.getFieldValue(user.companyId, 
/*  76 */       4);
/*  77 */     String password = companyExtManager.getFieldValue(user.companyId, 
/*  78 */       5);
/*  79 */     String serverIP = companyExtManager.getFieldValue(user.companyId, 
/*  80 */       6);
/*     */ 
/*  82 */     if ((companyId2 == null) || (companyId2.trim().length() == 0) || 
/*  83 */       (password == null) || (password.trim().length() == 0)) {
/*  84 */       logger.warn("not set companyId or passwrod");
/*  85 */       showErrorMessage(response, "系统设置中，没有设置呼叫中心账号和密码信息");
/*  86 */       return;
/*     */     }
/*     */ 
/*  89 */     if (((seatNum == null) || (seatNum.trim().length() == 0)) && 
/*  90 */       (!user.isAdmin) && (user.isGroupAdmin))
/*     */     {
/*  93 */       UserVOIPManager manager = new UserVOIPManager();
/*  94 */       List items = manager
/*  95 */         .getUsersVOIPInfos(user.companyId);
/*     */ 
/*  97 */       if ((items == null) || (items.size() == 0)) {
/*  98 */         logger.warn("该公司中，没有设置呼叫中心坐席账号, companyId " + 
/*  99 */           user.companyId);
/* 100 */         showErrorMessage(response, "该员工没有设置呼叫中心账号");
/* 101 */         return;
/*     */       }
/*     */ 
/* 104 */       CompanyInfo company = super.getCompany(request);
/* 105 */       if (company == null) {
/* 106 */         logger.warn("company is null ");
/* 107 */         showErrorMessage(response, "通话记录获得失败");
/* 108 */         return;
/*     */       }
/*     */ 
/* 112 */       for (Object itemO : items) {
            Map item = (Map)itemO;
/* 113 */         int groupId = ((Integer)item.get("GroupId")).intValue();
/* 114 */         if (company.isGroupAdmin(user, groupId))
/*     */         {
/* 117 */           if ((seatNum == null) || (seatNum.length() == 0))
/* 118 */             seatNum = (String)item.get("UserName");
/*     */           else {
/* 120 */             seatNum = seatNum + "," + (String)item.get("UserName");
/*     */           }
/*     */         }
/*     */       }
/*     */ 
/*     */     }
/*     */ 
/* 127 */     Date startDate = null;
/* 128 */     Date endDate = null;
/* 129 */     if ((beginDate != null) && (beginDate.trim().length() > 0)) {
/* 130 */       String[] arr = beginDate.split("~");
/* 131 */       int len = arr.length;
/* 132 */       if (len >= 1) {
/* 133 */         startDate = Util.str2Date(arr[0]);
/* 134 */         endDate = null;
/* 135 */         if (len > 1) {
/* 136 */           endDate = Util.str2Date(arr[1].trim());
/*     */         }
/*     */       }
/*     */     }
/*     */ 
/* 141 */     String body = PhoneBoxUtil.getCallLog(serverIP, companyId2, password, 
/* 142 */       seatNum, phone, startDate, endDate, minTime, maxTime, offset);
/*     */ 
/* 144 */     out.println(body);
/* 145 */     out.flush();
/* 146 */     out.close();
/*     */   }
/*     */ }

/* Location:           C:\E\referenceProject\CRM参考\qikebao\WEB-INF\lib\qikebao.jar
 * Qualified Name:     com.newcrm.webapi.sub.ListAllCallRecords
 * JD-Core Version:    0.6.1
 */